package br.com.pb.bymychef.persistencia.bean;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name="tb_ingrediente")
@SequenceGenerator(name = "S_TB_INGREDIENTE", sequenceName = "S_TB_INGREDIENTE", initialValue = 0, allocationSize = 1)
public class Ingrediente {
    
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "S_TB_INGREDIENTE")
    @Column(name="idIngrediente")
    private Long idIngrediente;
    @Column(name="nome", nullable=false, length=255)
    private String nomeIngrediente;
    @Column(name="descricao", nullable=true, length=255)
    private String descIngrediente;
    @ManyToOne(fetch=FetchType.LAZY, optional=false)
    @JoinColumn(name="idReceita")
    @JoinTable(name="tb_ingrediente")
    private Receita receita;
    
    public Long getIdIngrediente() {
        return idIngrediente;
    }
    public void setIdIngrediente(Long idIngrediente) {
        this.idIngrediente = idIngrediente;
    }
    public String getNomeIngrediente() {
        return nomeIngrediente;
    }
    public void setNomeIngrediente(String nomeIngrediente) {
        this.nomeIngrediente = nomeIngrediente;
    }
    public String getDescIngrediente() {
        return descIngrediente;
    }
    public void setDescIngrediente(String descIngrediente) {
        this.descIngrediente = descIngrediente;
    }
    
    @Override
    public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result
		+ ((idIngrediente == null) ? 0 : idIngrediente.hashCode());
	return result;
    }
    @Override
    public boolean equals(Object obj) {
	if (this == obj)
	    return true;
	if (obj == null)
	    return false;
	if (getClass() != obj.getClass())
	    return false;
	Ingrediente other = (Ingrediente) obj;
	if (idIngrediente == null) {
	    if (other.idIngrediente != null)
		return false;
	} else if (!idIngrediente.equals(other.idIngrediente))
	    return false;
	return true;
    }
    
}
